<template>
<!-- 借款申请 -->
   <div>
        <el-row>
           <el-col :span="24">
                <div class="grid-content bg-purple-dark">
                    <div class="kuang"></div>
                    <span style=" padding-left:40px;" >报销申请</span>
                    <div class="xian"></div>
                    <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="160px" style="margin-top:30px" class="demo-ruleForm">
                        <el-form-item label="发起人" prop="sponsorId">
                            <!-- 选择抄送人start -->
                     
                            <div class="avatar-uploader">
                                <!-- 选中负责人后展示start -->
                                <div v-if="selectedUser!=''" >
                                    <img  :src="selectedUser.icon" class="avatar" @click="headPage=true">
                                    <span style="position: relative;top: -17px;left: 20px;">{{ selectedUser.nickName }}
                                        <span style="margin-left: 26px;cursor: pointer;" @click="deUser">X</span>
                                    </span>
                                </div>
                                <!-- 选中抄送人后展示end -->
                                <!-- 负责人未选中展示 -->
                                <i v-else @click="headPage=true" class="el-icon-plus avatar-uploader-icon"></i>
                            </div>
                        

                        <el-dialog
                          v-loading="loading"
                          element-loading-text="拼命加载中"
                          element-loading-spinner="el-icon-loading"
                          element-loading-background="rgba(0, 0, 0, 0.8)"
                          :visible.sync="headPage"
                          width="50%"
                          :show-close="false">
                          <el-breadcrumb separator-class="el-icon-arrow-right">
                              <!-- 步骤条start -->
                              <el-breadcrumb-item  v-for="(value,index) in headNavs" :key="index" @click="upNav(index)">
                                  <el-button v-if="persons.id==undefined" size="mini" style="border: 0px;" @click="upNav(index)">{{ value }}</el-button>
                              </el-breadcrumb-item>
                              <!-- 步骤条end -->
                              <br>
                              <br>
                              <br>
                              <!-- 展示右边所选中的用户start -->
                              <div style="float: right;margin-top: -70px;margin-right:30%;color: black;">
                                  已选择<span v-if="selectedUser!=''">1</span><span v-else>0</span>位联系人
                                  <br>
                                  <br>
                                  <br>
                              </div>
                              <!-- 展示选中的用户 -->
                              <div  v-if="selectedUser!=''" class="architecture" style="height: 50px;float: right;    position: relative;top: 12px;right: 50px;">
                                  <img style="width: 30px;height: 30px;position: relative;top: 10px;" :src="selectedUser.icon"/>
                                  <span style="margin-left: 17%;color: black;color: black;font-size: 10px;display: block;margin-top: -20px;">
                                      {{ selectedUser.nickName }}<br><br>
                                      {{ selectedUser.tposition.deptName }}
                                      <span style="float: right;margin-top: -10px;margin-right: 20px;cursor: pointer;" @click="deUser">X</span>
                                  </span>
                                  
                              </div>
                              <!-- 展示右边所选中的用户end -->
                              <!-- 展示左边信息start -->
                              <!-- 展示部门和人数start -->
                              <div class="architecture" style="line-height: 39px;" v-for="(value,perIndex) in persons" :key="perIndex" @click="selectArchitecture(value.deptName)">
                                  <div class="log">
                                      <img src="https://cdn7.axureshop.com/demo2023/2236859/images/%E8%AF%B7%E5%81%87/u2303.svg" />
                                  </div>
                                  <span style="margin-left: 5%;color: black;">
                                      {{ value.deptName }}
                                  </span>
                                  &nbsp;&nbsp;&nbsp;({{ value.deptCount }})
                                  <span style="float: right;margin-right: 20px;">
                                      ＞
                                  </span>
                              </div>
                              <!-- 展示部门和人数end -->
                              <br>
                              <!-- 展示当前所选部门的所有用户start -->
                              <div v-if="users.length!=0">
                                  <div :class="[selectArchitectureCss != userIndex ?'architecture': '',selectArchitectureCss == userIndex ? 'architectureActe':'']" style="height: 50px;"  v-for="(myUser,userIndex) in users" :key="userIndex" @click="selectUser(userIndex)">
                                      <el-radio style="width: 80%;height: 100%;" v-model="selectId" :label="userIndex">
                                          &nbsp;&nbsp;&nbsp;
                                          <img style="width: 30px;height: 30px;position: relative;top: 10px;" :src="myUser.icon"/>
                                          <span style="margin-left: 5%;color: black;font-size: 10px;float: left;position: relative;top: 12px;left: 110px;">
                                              {{ myUser.nickName }}<br><br>
                                              {{ myUser.tposition.deptName }}
                                          </span>
                                          
                                      </el-radio>
                                      <span>
                                              ＞
                                      </span>
                                  </div>
                              </div>
                              <!-- 展示当前所选部门的所有用户start -->
                              <!-- 展示左边信息end -->
                              
                          </el-breadcrumb>

                          <!-- 竖直分割线 -->
                          <div class="myHr"></div>
                          
                          
                          <span slot="footer" class="dialog-footer">
                              <el-button @click="headPage = false">取 消</el-button>
                              <el-button type="primary" @click="headPage = false">确 定</el-button>
                          </span>
                      </el-dialog>
                  <!-- 选择负责人end -->
                        </el-form-item>
                        <el-form-item label="用款日期" prop="startTime">
                            <el-date-picker
                            v-model="ruleForm.startTime"
                            type="date"
                            placeholder="选择日期">
                            </el-date-picker>
                        </el-form-item>
                        
                         <el-form-item label="借款金额">
                            <el-input v-model="ruleForm.expenseMoney" style="width:400px" placeholder="请输入"></el-input>
                        </el-form-item>
                         <el-form-item label="备注">
                            <el-input type="textarea" :rows="4" v-model="ruleForm.remark" style="width:400px"></el-input>
                        </el-form-item>
                    </el-form>

                    <br/><br/>
                    <div class="kuang"></div>
                    <span style=" padding-left:40px;" >审批记录</span>
                    <div class="xian"></div>
                    <div class="kuai2">
                        <div style="height: 300px;">
                            <el-timeline >
                                <el-timeline-item color="#409EFF">发起</el-timeline-item>
                                <el-timeline-item color="#67C23A">
                                    审批人 &nbsp;&nbsp;
                                    <el-tag size="small" effect="plain" >依次审批</el-tag>
                                    <br/><br/>
                                    <el-select v-model="ruleForm.approver" multiple placeholder="请选择" style="width:100px">
                                        <el-option
                                        v-for="item in options"
                                        :key="item.id"
                                        :label="item.nickName"
                                        :value="item.id">
                                        </el-option>
                                    </el-select>
                                </el-timeline-item>
                                <el-timeline-item color="#E6A23C">抄送人
                                    <br/><br/>
                                    <div class="avatar-uploader">
                                            <!-- 选中负责人后展示start -->
                                            <div v-if="selectedUser2!=''" >
                                                <img  :src="selectedUser2.icon" class="avatar" @click="headPage2=true">
                                                <span style="position: relative;top: -17px;left: 20px;">{{ selectedUser2.nickName }}
                                                    <span style="margin-left: 26px;cursor: pointer;" @click="deUser2">X</span>
                                                </span>
                                            </div>
                                            <!-- 选中抄送人后展示end -->
                                            <!-- 负责人未选中展示 -->
                                            <i v-else @click="headPage2=true" class="el-icon-plus avatar-uploader-icon"></i>
                                        </div>
                                        <el-dialog
                                            v-loading="loading"
                                            element-loading-text="拼命加载中"
                                            element-loading-spinner="el-icon-loading"
                                            element-loading-background="rgba(0, 0, 0, 0.8)"
                                            :visible.sync="headPage2"
                                            width="50%"
                                            :show-close="false">
                                            <el-breadcrumb separator-class="el-icon-arrow-right">
                                                <!-- 步骤条start -->
                                                <el-breadcrumb-item  v-for="(value,index) in headNavs" :key="index" @click="upNav(index)">
                                                    <el-button v-if="persons.id==undefined" size="mini" style="border: 0px;" @click="upNav(index)">{{ value }}</el-button>
                                                </el-breadcrumb-item>
                                                <!-- 步骤条end -->
                                                <br>
                                                <br>
                                                <br>
                                                <!-- 展示右边所选中的用户start -->
                                                <div style="float: right;margin-top: -70px;margin-right:30%;color: black;">
                                                    已选择<span v-if="selectedUser2!=''">1</span><span v-else>0</span>位联系人
                                                    <br>
                                                    <br>
                                                    <br>
                                                </div>
                                                <!-- 展示选中的用户 -->
                                                <div  v-if="selectedUser2!=''" class="architecture" style="height: 50px;float: right;    position: relative;top: 12px;right: 50px;">
                                                    <img style="width: 30px;height: 30px;position: relative;top: 10px;" :src="selectedUser2.icon"/>
                                                    <span style="margin-left: 17%;color: black;color: black;font-size: 10px;display: block;margin-top: -20px;">
                                                        {{ selectedUser2.nickName }}<br><br>
                                                        {{ selectedUser2.tposition.deptName }}
                                                        <span style="float: right;margin-top: -10px;margin-right: 20px;cursor: pointer;" @click="deUser2">X</span>
                                                    </span>
                                                    
                                                </div>
                                                <!-- 展示右边所选中的用户end -->
                                                <!-- 展示左边信息start -->
                                                <!-- 展示部门和人数start -->
                                                <div class="architecture" style="line-height: 39px;" v-for="(value,perIndex) in persons" :key="perIndex" @click="selectArchitecture(value.deptName)">
                                                    <div class="log">
                                                        <img src="https://cdn7.axureshop.com/demo2023/2236859/images/%E8%AF%B7%E5%81%87/u2303.svg" />
                                                    </div>
                                                    <span style="margin-left: 5%;color: black;">
                                                        {{ value.deptName }}
                                                    </span>
                                                    &nbsp;&nbsp;&nbsp;({{ value.deptCount }})
                                                    <span style="float: right;margin-right: 20px;">
                                                        ＞
                                                    </span>
                                                </div>
                                                <!-- 展示部门和人数end -->
                                                <br>
                                                <!-- 展示当前所选部门的所有用户start -->
                                                <div v-if="users.length!=0">
                                                    <div :class="[selectArchitectureCss != userIndex ?'architecture': '',selectArchitectureCss == userIndex ? 'architectureActe':'']" style="height: 50px;"  v-for="(myUser,userIndex) in users" :key="userIndex" @click="selectUser2(userIndex)">
                                                        <el-radio style="width: 80%;height: 100%;" v-model="selectId" :label="userIndex">
                                                            &nbsp;&nbsp;&nbsp;
                                                            <img style="width: 30px;height: 30px;position: relative;top: 10px;" :src="myUser.icon"/>
                                                            <span style="margin-left: 5%;color: black;font-size: 10px;float: left;position: relative;top: 12px;left: 110px;">
                                                                {{ myUser.nickName }}<br><br>
                                                                {{ myUser.tposition.deptName }}
                                                            </span>
                                                            
                                                        </el-radio>
                                                        <span>
                                                                ＞
                                                        </span>
                                                    </div>
                                                </div>
                                                <!-- 展示当前所选部门的所有用户start -->
                                                <!-- 展示左边信息end -->
                                                
                                            </el-breadcrumb>

                                            <!-- 竖直分割线 -->
                                            <div class="myHr"></div>
                                            
                                            
                                            <span slot="footer" class="dialog-footer">
                                                <el-button @click="headPage2 = false">取 消</el-button>
                                                <el-button type="primary" @click="headPage2 = false">确 定</el-button>
                                            </span>
                                        </el-dialog>
                                    <!-- 选择负责人end -->
                                </el-timeline-item>
                            </el-timeline>
                            <el-row style=" position: relative;left:900px">
                            <el-button @click="handleEdit">取消</el-button>
                            <el-button type="primary" @click="onSubmit">提交</el-button>
                            </el-row>
                        </div>
                    </div>
                </div>
            </el-col>
        </el-row>
   </div>
</template>
<script>
import axios from 'axios'
export default {
    data(){
        return{
            options:[],
            ruleForm: {
            sponsorId:'',
            moneyType:"2",
            status:"1",
            expenseMoney: '',
            startTime:'',
            carbon:'',
            approver:'',
            remark:''
            },
            rules: {
                startTime:[
                    { required: true, message: '请选择', trigger: 'change' }
                ],
                sponsorId:[
                    { required: true, message: '请选择', trigger: 'change' }
                ]
            },
             // 获取抄送人start
            headPage:false,//开启选择抄送人页面
            headPage2:false,
            headNavs:["组织架构"],//步骤条
            persons:[],//部门和部门人数
            users:[],//所选部门的人员
            loading:false,//加载开启和关闭
            selectArchitectureCss:-1,//选中指定行后开启指定的css
            selectId:-1,//单选框
            selectedUser:"",//选中的用户
            selectedUser2:"",//选中的用户
            //  获取抄送人end
            
        }
    },
    created(){
      this.getDept();//获取部门
      this.getUserList();
    },
    methods: {
        //id传一个当前登录人的id
            getUserList() {
                var a=JSON.parse(localStorage.getItem("user"))
                axios.get("demo/findTUserList?id="+a.id)
                    .then((res) => {
                        console.log(res);
                        this.options = res.data;
                    })
            },
        // 负责人start
        // 更新步骤条
        upNav(index){
            this.headNavs = this.headNavs.slice(0,index+1);
            if("组织架构"==this.headNavs){
                this.loading = true;
                this.users = [];
                this.getDept();
            }
        },
        // 获取部门及部门人数
        getDept(){
            this.selectId=-1;
            this.deUser();
            axios.post("/ReplacementCard/findDept")
            .then((res)=>{
                this.persons = res.data.rows;
                this.loading = false;
            })
        },
        // 获取所选择部门的用户信息
        selectArchitecture(value){
            this.loading = true;
            this.persons = [];
            this.headNavs.push(value);
            var data = new FormData();
            data.append("name",value)
            axios.post("/ReplacementCard/findUserAndDept",data)
            .then((res)=>{
                this.users = res.data.rows;
                if(this.users!=[]){
                    this.loading = false;
                }
            })

        },
        //选中发起人
        selectUser(index){
            
            this.selectArchitectureCss = index;
            this.selectedUser = this.users[index];
            this.ruleForm.sponsorId = this.selectedUser.id;
            console.log("发起人"+this.ruleForm.sponsorId)
        },
        //删除用户
        deUser(){
            this.selectId=-1;
            this.selectedUser="";
            this.selectArchitectureCss = -1;
            this.ruleForm.sponsorId = "";
        },
         //选中抄送人
        selectUser2(index){
            this.selectArchitectureCss = index;
            this.selectedUser2 = this.users[index];
            this.ruleForm.carbon = this.selectedUser2.id;
            console.log("抄送人"+this.ruleForm.carbon)
        },
        //删除用户
        deUser2(){
            this.selectId=-1;
            this.selectedUser2="";
            this.selectArchitectureCss = -1;
            this.ruleForm.carbon = "";
        },
        //负责人end
        //添加
        onSubmit(){
          var approver="";
          for (const value of this.ruleForm.approver) {
              approver==""?approver+=value:approver+=","+value
          }
          this.ruleForm.approver=approver
          axios
          .post("ExpenseAccount/addExpenseAccount", this.ruleForm)
          .then((res) => {
              //待定
              console.log(res.data);
              if (res.data.code == 200) {
              this.$message({
                  message: "恭喜你，" + res.data.msg,
                  type: "success",
              });
              } else {
              this.$message.error("错了哦，" + res.data.msg);
              }
          });
        },
         handleEdit(){
             this.$router.push("/BorrowMoneyList"); //返回                                                                    
        }
    }

}
</script>

<style scoped>
.el-row {
    margin-bottom: 20px;
  }
  .el-col {
    border-radius: 4px;
  }
  .kuai2{
         width:1000px;
        height:300px;
        /* border: 1px red solid; */
        position: relative;
        top: 30px;
        left: 55px;
    }
  .bg-purple-dark {
    background: white;
    height: 1000px;
  }
  .bg-purple {
    background: #d3dce6;
  }
  .bg-purple-light {
    background: #e5e9f2;
  }
  .grid-content {
    border-radius: 4px;
    min-height: 36px;
  }
  .row-bg {
    padding: 10px 0;
    background-color: #f9fafc;
  }
   .kuang{
        width: 4.5px;
        height: 25px;
        background-color: #409EFF;
        margin-left: 30px;
        position: relative;
        top: 23px;
    }
    .xian{
        width: 1200px;
        height: 2px;
        background-color: #EBEEF5;
        margin-left: 40px;
        margin-top: 15px;
       
    }
     /* 获取负责人start */
    .architecture{
        width: 271px;
        height: 39px;
        padding-left: 20px;
        border-radius: 5px;
    }
    .architecture:hover{
        background-color: #f8f8f8;
    }
    .architectureActe{
        width: 271px;
        height: 39px;
        line-height: 39px;
        padding-left: 20px;
        border-radius: 5px;
        background-color: rgba(231, 244, 255, 1);;
    }
    /* 竖着的水平线 */
    .myHr{
        border-left: 2px solid#989DAA;;
        height:100%;
        left: 48%;
        top: 0px;
        position: absolute;
    }

    .log{
        width: 27px;
        height: 27px;
        background-color: rgba(158, 208, 255, 1);
        float: left;
        position: relative;
        top: 15%;
        border-radius: 50%;
    }
    .log img{
        width: 13px;
        height: 13px;
        position: relative;
        bottom: 15%;
        left: 25%;
    }
    .avatar-uploader-icon[data-v-146889d1]{
        border: 1px solid rgba(198, 201, 208, 1);
        background-color: rgba(248, 248, 248, 1);
        border-radius: 50%;
    }
    .avatar-uploader-icon {
        font-size: 20px;
        color: #8c939d;
        width: 50px;
        height: 50px;
        line-height: 50px;
        text-align: center;
    }
    /* 获取负责人end */
</style>